/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "POSSetup")
@XmlRootElement
public class POSSetup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "tasterDiscount")
    private float tasterDiscount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enableLoyalty")
    private boolean loyaltyProgram;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enableBDayBeer")
    private boolean birthdayBeer;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enableGrowlerProgram")
    private boolean growlerProgram;
    @Basic(optional = false)
    @NotNull
    @Column(name = "valuePerPoint")
    private float valuePerPoint;
    @Basic(optional = false)
    @NotNull
    @Column(name = "growlerCount")
    private int growlerCount;
    @OneToOne
    @JoinColumn(name = "tasterGlassware", referencedColumnName = "glassWareID", nullable=true)
    private POSGlassWare glassware;
    @OneToOne
    @JoinColumn(name = "growlerDiscount", referencedColumnName = "posDiscountID", nullable=true)
    private POSDiscount growlerDiscount;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="posJTSetupToProdTemp",
        joinColumns={ @JoinColumn(name="id", referencedColumnName="id")},
        inverseJoinColumns={ @JoinColumn(name="templateID", referencedColumnName="templateID", unique=true)}
    )
    private List<POSProdTemplate> productTemplate;

    public POSSetup() {
    }

    public POSSetup(Integer id) {
        this.id = id;
    }

    public POSSetup(Integer id, float tasterDiscount) {
        this.id = id;
        this.tasterDiscount = tasterDiscount;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public float getTasterDiscount() {
        return tasterDiscount;
    }

    public void setTasterDiscount(float tasterDiscount) {
        this.tasterDiscount = tasterDiscount;
    }

    public boolean isLoyaltyProgram() {
        return loyaltyProgram;
    }

    public void setLoyaltyProgram(boolean loyaltyProgram) {
        this.loyaltyProgram = loyaltyProgram;
    }

    public boolean isBirthdayBeer() {
        return birthdayBeer;
    }

    public void setBirthdayBeer(boolean birthdayBeer) {
        this.birthdayBeer = birthdayBeer;
    }

    public boolean isGrowlerProgram() {
        return growlerProgram;
    }

    public void setGrowlerProgram(boolean growlerProgram) {
        this.growlerProgram = growlerProgram;
    }

    public float getValuePerPoint() {
        return valuePerPoint;
    }

    public void setValuePerPoint(float valuePerPoint) {
        this.valuePerPoint = valuePerPoint;
    }

    public int getGrowlerCount() {
        return growlerCount;
    }

    public void setGrowlerCount(int growlerCount) {
        this.growlerCount = growlerCount;
    }

    public POSGlassWare getGlassware() {
        return glassware;
    }

    public void setGlassware(POSGlassWare glassware) {
        this.glassware = glassware;
    }

    public POSDiscount getGrowlerDiscount() {
        return growlerDiscount;
    }

    public void setGrowlerDiscount(POSDiscount growlerDiscount) {
        if(growlerDiscount != null && growlerDiscount.getId() != null){
            this.growlerDiscount = growlerDiscount;
        }
    }

    public List<POSProdTemplate> getProductTemplate() {
        return productTemplate;
    }

    public void setProductTemplate(List<POSProdTemplate> productTemplate) {
        this.productTemplate = productTemplate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSSetup)) {
            return false;
        }
        POSSetup other = (POSSetup) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.possetup[ id=" + id + " ]";
    }
}
